home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 21.zip / BS1 part 21 / Professional Page v4.0 (1993)(Gold Disk)(Disk 1 of 4)[HD].7z / Professional Page v4.0 (1993)(Gold Disk)(Disk 1 of 4)[HD].adf / rexx.lzh / TableImport.pprx < prev    next >
Text File  |  1993-01-28  |  3KB  |  133 lines

  1. /*
  2. @BTableImport  @P@ICopyright Gold Disk Inc. January, 1992
  3.  
  4. This Genie will read a data file and produce a table. Values must be between quotes and comma or tab separated with no extra spaces between entries.
  5. (Ex: "Value 1","Value 2","Value 3"...)
  6. */
  7. numeric digits 8
  8. cr  = '0a'x
  9. address command
  10. call SafeEndEdit.rexx()
  11. call ppm_AutoUpdate(0)
  12.  
  13. units = ppm_GetUnits()
  14. if units = 3 then
  15.     call ppm_SetUnits(1)
  16.  
  17. signal on halt
  18. signal on break_c
  19. signal on break_e
  20. signal on break_d
  21.  
  22. box = ppm_ClickOnBox("Click on box in which to import table.")
  23.  
  24. if box = 0 then
  25. do
  26.     call ppm_Inform(1, "No box selected",)
  27.     call ppm_ClearStatus()
  28.     exit
  29. end
  30.  
  31. /*  extract box attributes  */
  32. boxsize = ppm_GetBoxSize(box)
  33. boxpos = ppm_GetBoxPosition(box)
  34.  
  35. if ppm_Inform(2, "Delete original box?",) = 1 then call ppm_DeleteBox(box)
  36.  
  37. filename = ppm_GetFileName("Select file to be imported", "","")
  38. if filename = '' then exit_msg()
  39.  
  40. if ~open(file, filename, "r") then exit_msg("Unable to open file: "filename)
  41.  
  42. line = readln(file)
  43.  
  44. /*  Determine field delimiters  */
  45. if pos('","', line) ~= 0 then delimiter = '","'
  46. else if pos('09'x, line) ~= 0 then delimiter = "'09'x"
  47. else exit_msg("File must be either comma delimited or tab delimited.")
  48.  
  49. /*  determine number of columns */
  50. cols = 1
  51. do while line ~ = ''
  52.         interpret "parse var line matrix.1.cols "delimiter" line"
  53.         if delimiter = '","' then matrix.1.cols = strip(matrix.1.cols, b, '"')
  54.        cols = cols + 1
  55. end
  56.  
  57. cols = cols - 1
  58. rows  = 1
  59.  
  60. do while ~eof(file)
  61.     line = readln(file)
  62.     if line = '' then iterate
  63.     rows = rows + 1
  64.     do col = 1 to cols
  65.         interpret "parse var line matrix."rows"."col" "delimiter" line"
  66.         if delimiter = '","' then matrix.rows.col = strip(matrix.rows.col, b, '"')
  67.         if line = '' then leave
  68.     end
  69. end
  70.  
  71. selection   = "Right Justify Numbers"cr"Make Grid Lines"
  72. selection   = upper(ppm_SelectFromList("Select Options", 30, 5, 1, selection))
  73. if selection = '' then exit_msg()
  74.  
  75. if pos(GRID, selection) ~= 0 then grid = 1
  76. else grid       = 0
  77. if pos(RIGHT, selection) ~= 0 then right = 1
  78. else right  = 0
  79.  
  80. call ppm_SetSize(12)
  81. boxwidth = word(boxsize, 1) / cols
  82. boxheight = word(boxsize, 2) / rows
  83. boxleft = word(boxpos, 1)
  84. boxtop = word(boxpos, 2)
  85. left = boxleft
  86. top = boxtop
  87.  
  88. do row = 1 to rows
  89.     do col = 1 to cols
  90.         call ppm_ShowStatus("Working on row:"row" column:"col)
  91.         box = ppm_CreateBox(left, top, boxwidth, boxheight, 0,)
  92.         left    = left  + boxwidth
  93.         call ppm_SetBoxMargins(box, .1, .1, .1, .1)
  94.         if grid then
  95.         do
  96.             call ppm_SetBoxFrame(box, 1)
  97.             call ppm_SetBoxFrameData(box, "black", "black", .5, 1, 0)
  98.         end
  99.  
  100.                 if matrix.row.col = "" then matrix.row.col = " "
  101.  
  102.         if right & datatype(matrix.row.col) = 'NUM' then
  103.             call ppm_TextIntoBox(box, ""strip(matrix.row.col))
  104.         else
  105.             call ppm_TextIntoBox(box, ""strip(matrix.row.col))
  106.     end
  107.     left    = boxleft
  108.     top     = top + boxheight
  109. end
  110.  
  111. exit_msg("Done")
  112.  
  113. break_d:
  114. break_e:
  115. break_c:
  116. halt:
  117.     call exit_msg("User aborted Genie!")
  118.  
  119. exit_msg: procedure expose units
  120. do
  121.     parse arg message
  122.  
  123.     call ppm_ClearStatus()
  124.  
  125.     if message ~= '' then
  126.         call ppm_Inform(1, message,)
  127.  
  128.    call ppm_SetUnits(units)
  129.     call ppm_AutoUpdate(1)
  130.     exit
  131. end
  132.  
  133.